/**
 * @author xana
 * @date 2021/6/6
 */

#ifndef DNPLAYER_MKFFMPEG_H
#define DNPLAYER_MKFFMPEG_H


#include <pthread.h>
#include <android/native_window.h>
#include "JavaCallHelper.h"
#include "AudioChannel.h"
#include "VideoChannel.h"

extern "C" {
#include <libavformat/avformat.h>
#include <libavutil/time.h>

}


class Mkffmpeg {
public:
    Mkffmpeg(JavaCallHelper *javaCallHelper, const char *dataSource);

    ~Mkffmpeg();

    void prepare();

    void prepareFFmpeg();

    void start();

    void play();

    void setRenderCallback(RenderFrame renderFrame);

    void stop();

    uint64_t getDuration() const {
        return duration;
    }

    bool playing() const{
        return isPlaying;
    }

    uint64_t getCurrent() const;

private:
    char *url;
    JavaCallHelper *javaCallHelper;

    pthread_t pid_prepare;
    pthread_t pid_play;
    AVFormatContext *formatContext;

    int64_t duration;

    RenderFrame renderFrame;

    AudioChannel *audioChannel = 0;
    VideoChannel *videoChannel = 0;

    bool isPlaying;

};


#endif //DNPLAYER_MKFFMPEG_H
